import { ref } from "vue"
import store from "@/store"
import { defineStore } from "pinia"
import { getUserDataApi } from "@/api/user"
export const useUserListStore = defineStore(
  "re",
  () => {
    const userListStore = ref<string[]>([])

    const setUserList = (value: string[]) => {
      userListStore.value = value
    }
    const getUserListFn = async () => {
      await getUserDataApi({
        page: 1,
        size: 10000,
        name: undefined,
        department: "",
        team: "",
        role: ""
        // phone: searchData.phone || undefined
      }).then((res: any) => {
        setUserList(res.data.userList)
      })
    }

    return {
      userListStore,
      setUserList,
      getUserListFn
    }
  },
  {
    persist: {
      enabled: true,
      strategies: [
        {
          storage: localStorage
          // paths: ["jobListStore", "authListStore"] //指定要长久化的字段
        }
      ]
    }
  }
)
/** 在 setup 外使用 */
export function useUserListStoreHook() {
  return useUserListStore(store)
}
